package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.CommentMy;
import cn.xmy.demo01.pojo.Imgs;
import cn.xmy.demo01.pojo.Shops;
import cn.xmy.demo01.service.CommentsDaoService;
import cn.xmy.demo01.service.ImgsDoaService;
import cn.xmy.demo01.service.ShopDaoService;
import cn.xmy.demo01.service.impl.CommentDaoImplService;
import cn.xmy.demo01.service.impl.ImgDaoImplService;
import cn.xmy.demo01.service.impl.ShopServiceDaoImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/findCommentServlet")
public class FindCommentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id=req.getParameter("id");
        ShopDaoService shopServiceDao=new ShopServiceDaoImpl();
        List<Shops> shopss=null;
        //img
        ImgsDoaService imgsDoaService=new ImgDaoImplService();
        List<Imgs>imgs=null;
        //Comment
        CommentsDaoService commentDaoService=new CommentDaoImplService();
        List<CommentMy>commentMIES=null;


        try {
            shopss=shopServiceDao.FindComment(id);
            imgs=imgsDoaService.Findimgs(id);
            commentMIES=commentDaoService.FindComment(id);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        req.setAttribute("shopss",shopss);
        req.setAttribute("imgs",imgs);
        req.setAttribute("commentMIES",commentMIES);
        req.setAttribute("id",id);
        //存储一个头像
        HttpSession session = req.getSession();
        session.setAttribute("id", id);
        req.getRequestDispatcher("comment.html").forward(req,resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
